package com.java.controller;

import com.java.service.UserService;
import com.java.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author: LR
 * @Date: 2018/6/10
 * @Time: 10:30
 */
@Controller
public class LoginAction {
    /**
     *  @ModelAttribute自动将前端数据装入实体类中
     *  */
    @Autowired
    private UserService  userService;

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    @RequestMapping("/loginAction")

    public String login(@ModelAttribute("user")User user, Model model) {
        this.getUserService().selectUser(user);
        String name = "张三";
        String pass = "111111";
        if (name != null && name.equals(user.getUsername()) && user.getPassword() != null &&  user.getPassword().equals(pass)) {
            model.addAttribute("username",user.getUsername());
            return "success";
        }
        return "failed";
    }
}
